import Vue from 'vue'
const type = {
  // 获取列表
  typeList: function typeList(ip, postdata) {
    return Vue.http.get(ip, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 添加类别
  typeAdd: function typeAdd(ip, postdata) {
    // console.log(postdata, ip)
    return Vue.http.post(ip, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 删除类别
  typeDel: function typeDel(ip, postdata) {
    // console.log(postdata, ip)
    var ipStr = ip + "/" + postdata.id
    return Vue.http.post(ipStr, postdata).then(response => {
      // console.log('end')
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 排序类别
  typeSort: function typeSort(ip, postdata) {
    // console.log(postdata, ip)
    var ipStr = ip + "/" + postdata.id
    return Vue.http.post(ipStr, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  }
}

export default type
